package com.fatmeraid.controller.product;

import com.fatmeraid.common.result.Result;
import com.fatmeraid.domain.ProductImage;
import com.fatmeraid.service.ProductImageService;
import com.fatmeraid.vo.ProductImage.UploadImageVo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Tag(name = "商品图片管理管理")
@RestController
@RequestMapping("/productImage")
public class ProductImageController{

	@Autowired
	private ProductImageService productImageService;

	@Operation(summary = "上传商品图片")
	@PostMapping
	public Result<String> uploadProductImage(@RequestBody UploadImageVo uploadImageVo) {
		boolean result = productImageService.uploadProductImage(uploadImageVo);
		return Result.ok();
	}

	@Operation(summary = "获取商品图片列表")
	@GetMapping("/list/{productId}")
	public Result<List<ProductImage>> getProductImageList(@PathVariable Long productId) {
		List<ProductImage> result = productImageService.getProductImageList(productId);
		return Result.ok(result);
	}

	@Operation(summary = "删除商品图片")
	@DeleteMapping("/{id}")
	public Result<String> deleteProductImage(@PathVariable Long id) {
		boolean result = productImageService.deleteProductImage(id);
		if (!result) {
			return Result.fail();
		}
		return Result.ok();
	}
}
